# -- coding: utf-8 --
"""
# [Example] Miahx© 交互框架信息表示模型的 DDS 消息收发示例

**模块：MIAHX© / 框架基础服务层（FFST） / 交互框架信息表示模型（IFIRM）**

Version: 0.4.10,
Last updated: October 2, 2024

## Contributor(s)
* YAO Naiming <[naiming@iscas.ac.cn](mailto:naiming@iscas.ac.cn)>

## Change log
### v0.4.10
- .2: [新增] 重构实现

---
Copyright © 2024-2025 MIAHX Contributors, ISCAS, and ASIC. All Rights Reserved.
Licensed under Apache-2.0.
"""

import signal
import threading
import time

from loguru import logger

log = logger.bind()


def run(creator):
    def _shutting_down(signum, frame):
        log.warning('用户中断或终止')
        event.set()

    signal.signal(signal.SIGINT, _shutting_down)
    signal.signal(signal.SIGTERM, _shutting_down)

    event, threads = creator()
    assert isinstance(event, threading.Event)
    assert isinstance(threads, list)
    for t in threads:
        assert isinstance(t, threading.Thread)
        t.start()

    while not event.is_set():
        time.sleep(0.1)
